/*
* Copyright (C) Microsoft. All rights reserved.  
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not 
* use this file except in compliance with the License.  You may obtain a copy 
* of the License at http://www.apache.org/licenses/LICENSE-2.0  
* 
* THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
* WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
* MERCHANTABLITY OR NON-INFRINGEMENT. 
*
* See the Apache License, Version 2.0 for specific language governing 
* permissions and limitations under the License.
*
*/
#include "pch.h"
#include <baja/model/generic_model.h>

namespace baja { namespace model {

namespace b = baja;

generic_model::generic_model() :
    _genericTypeToken(0),
    _genericIdentity(0)
{

}

b::int32 generic_model::addGenericObserver(const std::shared_ptr<igeneric_model_observer>& observer)
{
    return _eventSource += observer;
}

void generic_model::removeGenericObserver(const std::shared_ptr<igeneric_model_observer>& observer)
{
    _eventSource -= observer;
}

void generic_model::removeGenericObserver(const b::int32& cookie)
{
    _eventSource -= cookie;
}

void generic_model::setGenericTypeToken(const b::uint32& genericTypeToken)
{
    _genericTypeToken = genericTypeToken;
}

b::uint32 generic_model::genericTypeToken()
{
    return _genericTypeToken;
}

void generic_model::setGenericIdentity(const b::uint32& genericIdentity)
{
    _genericIdentity = genericIdentity;
}

b::uint32 generic_model::genericIdentity()
{
    return _genericIdentity;
}

void generic_model::setGenericParent(const std::shared_ptr<igeneric_model>& parent)
{
    _genericParent = parent;
}

std::shared_ptr<igeneric_model> generic_model::genericParent()
{
    return _genericParent.lock();
}

void generic_model::fireChangedEvent()
{
    _eventSource.raise(
        [&](const std::shared_ptr<igeneric_model_observer>& observer, void* context)
        {
            observer->onChildChanged(_genericTypeToken, _genericIdentity);
        });
}

}} // baja::model